home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
vbpxen
/
pxmodule.bas
< prev
next >
Wrap
BASIC Source File
|
1991-10-07
|
14KB
|
417 lines
'
' Written by Steve Jackson
' 9152 Brabham Drive
' Huntington Beach, CA 92646
'
' Thanks to John Jaster for some of the dll definitions
'
' Most of the engine functions are defined here, but not all.
' One that I have not gotten to work is PxErrMsg because it returns
' a pointer. Visual Basic has no pointer types (that I know of).
' You might get it to work by get a pointer to windows memory and
' using that, but it is beyond me right now.
'
' This module is meant to be a general purpose visual basic interface
' to the Paradox engine DLL. To run it, you need the DLL from Paradox
' Engine. An example of usage is distributed in little video rental
' application called VVDEMO.
'
' Comments, questions are welcome. If you know of any ways I can
' earn a little extra income to purchase a faster computer (and with
' more memory) that would be welcome too.
'
'******* Declarations for Using the Paradox 3.5 Engine ******
Declare Function PXWinInit Lib "Pxengwin.dll" (ByVal Application$, ByVal Mode%) As Integer
Declare Function PXExit Lib "Pxengwin.dll" () As Integer
'************ TABLE FUNCTIONS *****************
Declare Function PXTblOpen Lib "Pxengwin.dll" (ByVal TblName$, TblHnd%, ByVal index%, ByVal change%) As Integer
Declare Function PXTblClose Lib "Pxengwin.dll" (ByVal TblHnd%) As Integer
'************* RECORD FUNCTIONS *******************
Declare Function PXRecAppend Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal RecHnd%) As Integer
Declare Function PXRecInsert Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal RecHnd%) As Integer
Declare Function PXRecUpdate Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal RecHnd%) As Integer
Declare Function PXRecDelete Lib "Pxengwin.dll" (ByVal TblHnd%) As Integer
Declare Function PXRecBufOpen Lib "Pxengwin.dll" (ByVal TblHnd%, RecHnd%) As Integer
Declare Function PXRecBufClose Lib "Pxengwin.dll" (ByVal RecHnd%) As Integer
Declare Function PXRecBufEmpty Lib "Pxengwin.dll" (ByVal RecHnd%) As Integer
Declare Function PXRecGet Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal RecHnd%) As Integer
Declare Function PXRecFirst Lib "Pxengwin.dll" (ByVal TblHnd%) As Integer
Declare Function PXRecLast Lib "Pxengwin.dll" (ByVal TblHnd%) As Integer
Declare Function PXRecNext Lib "Pxengwin.dll" (ByVal TblHnd%) As Integer
Declare Function PXRecPrev Lib "Pxengwin.dll" (ByVal TblHnd%) As Integer
Declare Function PXRecNum Lib "Pxengwin.dll" (ByVal TblHnd%, RecNum%) As Integer
Declare Function PXTblNRecs Lib "Pxengwin.dll" (ByVal TblHnd%, nRecs%) As Integer
'**************** FIELD FUNCTIONS ****************
Declare Function PXPutShort Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, ByVal sValue%) As Integer
Declare Function PXPutDoub Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, ByVal dValue#) As Integer
Declare Function PXPutLong Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, ByVal lValue&) As Integer
Declare Function PXPutAlpha Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, ByVal aValue$) As Integer
Declare Function PXPutBlank Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%) As Integer
Declare Function PXPutDate Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, ByVal inDate As Any) As Integer
Declare Function PXGetShort Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, sValue%) As Integer
Declare Function PXGetDoub Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, dValue#) As Integer
Declare Function PXGetLong Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, lValue&) As Integer
Declare Function PXGetAlpha Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, ByVal bufSize%, ByVal aValue$) As Integer
Declare Function PXFldBlank Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, Blank%) As Integer
Declare Function PXGetDate Lib "Pxengwin.dll" (ByVal RecHnd%, ByVal FldHnd%, outDate As Any) As Integer
Declare Function PXRecNFlds Lib "Pxengwin.dll" (ByVal TblHnd%, nFlds%) As Integer
Declare Function PXFldHandle Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal FldName$, FldHnd%) As Integer
Declare Function PXFldType Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal FldHnd%, ByVal BufSiz%, ByVal fldtype$) As Integer
Declare Function PXFldName Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal FldHnd%, ByVal BufSiz%, ByVal FldName$) As Integer
'*************** SEARCH FUNCTIONS *******************
Declare Function PXSrchKey Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal RecHnd%, ByVal nFlds%, ByVal Mode%) As Integer
Declare Function PXSrchFld Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal RecHnd%, ByVal FldNum%, ByVal Mode%) As Integer
'***************** MISCELLANEOUS FUNCTIONS ****************
Declare Function PXDateDecode Lib "Pxengwin.dll" (ByVal outDate As Any, mm%, dd%, yy%) As Integer
Declare Function PXDateEncode Lib "Pxengwin.dll" (ByVal mm%, ByVal dd%, ByVal yy%, pDate&) As Integer
' note: PXErrMsg returns a string, not an integer
Declare Function PXErrMsg Lib "Pxengwin.dll" (ByVal error_code%) As String
'******************* NETWORK FUNCTIONS ******************
Declare Function PXNetUserName Lib "Pxengwin.dll" (ByVal buffer%, UserName$) As Integer
Declare Function PXNetFileLock Lib "Pxengwin.dll" (ByVal FileName$, ByVal lockType%) As Integer
Declare Function PXNetFileUnlock Lib "Pxengwin.dll" (ByVal FileName$, ByVal lockType%) As Integer
Declare Function PXNetTblLock Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal lockType%) As Integer
Declare Function PXNetTblUnlock Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal lockType%) As Integer
Declare Function PXNetRecLock Lib "Pxengwin.dll" (ByVal TblHnd%, LockHnd%) As Integer
Declare Function PXNetRecUnlock Lib "Pxengwin.dll" (ByVal TblHnd%, ByVal LockHnd%) As Integer
Declare Function PXNetRecLocked Lib "Pxengwin.dll" (ByVal TblHnd%, Locked%) As Integer
Declare Function PXNetTblChanged Lib "Pxengwin.dll" (ByVal TblHnd%, Changed%) As Integer
Declare Function PXNetTblRefresh Lib "Pxengwin.dll" (ByVal TblHnd%) As Integer
'
' Variables used only in this module
'
' What must be defined in global: NUMBER_OF_TABLES
'
'
Dim hTable(NUMBER_OF_TABLES) As Integer
Dim hRecBuf(NUMBER_OF_TABLES) As Integer
Dim hRecLock(NUMBER_OF_TABLES) As Integer
Dim iTableIsClosed(NUMBER_OF_TABLES) As Integer
Dim alpha_field As String * 256
Dim px As Integer
Const PX_OK = 0
Const PX_ENDOFTABLE = 101
Const PX_STARTOFTABLE = 102
Const PX_RECNOTFOUND = 89
Const PX_KEYVIOL = 97
Const PX_RECDELETED = 50
Const PX_RECLOCKED = 9
Sub PXError (ByVal error_code As Integer)
'
' General purpose error trapping.
' If the error is not critical (that is, the database is OK),
' return to the user. Store message that they can retrieve if
' needed by calling dberrormsg().
'
' If the error is critical, processing cannot continue, and
' this routine will END THE PROGRAM
'
If error_code = PX_OK Then
Exit Sub
End If
'
' Non-critical errors:
'
Select Case error_code
Case PX_OK
Exit Sub
Case PX_ENDOFTABLE, PX_STARTOFTABLE, PX_KEYVIOL
Exit Sub
Case PX_RECNOTFOUND, PX_RECDELETED
Exit Sub
End Select
Msg$ = "Paradox database error code: " + Str$(error_code)
' alpha_field = PXErrMsg(error_code)
' Msg$ = Msg$ + alpha_field
MsgBox Msg$, 0 + 16, "Database Error"
End
End Sub
Function DBInit (ByVal AppName$) As Integer
'
' Start the paradox engine for windows
' for now always use mode of: PXSHARED
'
px = PXWinInit(AppName$, 2)
If px = 82 Then
DBInit = PX_OK
Exit Function
End If
If px Then
Msg$ = "Unable to start Paradox engine, code: " + Str$(px)
Msg$ = Msg$ + " Remember to type SHARE before starting Windows"
MsgBox Msg$, 0 + 16, "Database Initialization"
End
End If
DBInit = PX_OK
End Function
Function DBExit () As Integer
'
' Shutdown the paradox engine
'
DBExit = PXExit()
End Function
Function TableOpen (ByVal Tblnum%, ByVal TblName$)
'
' Open a table and allocate one record buffer for it.
' Application calls this ro